#ifndef ILRT_ALLOCATOR_H_
#define ILRT_ALLOCATOR_H_

#include <ilrt/Type.h>

namespace ilrt{
	namespace Allocator {
		template<typename T> class BlockAllocator : public illib::BlockAllocator::BasicAllocator {
		protected:
			void * data_;
			const char * name_;
		public:
			BlockAllocator(void * data, const char * name, Allocator * parent = 0) :
				BasicAllocator(alignof(T), parent),
				data_(data),
				name_(name)
			{

			}
			virtual ~BlockAllocator(){

			}
			T& create(size_t requestedSize, size_t &allocatedSize) {
				uint8_t * memory = BasicAllocator::allocate(requestedSize, allocatedSize);
				return *new(memory)T();
			}
			virtual bool release(T* ptr){
				return BasicAllocator::release(ptr);
			}
			virtual void * data(){
				return data_;
			}
			virtual const char * name(){
				return name_;
			}
		};

		template<typename T> class PoolAllocator : public illib::PoolAllocator::BasicAllocator {
		protected:
			void *data_;
			const char * name_;
		public:
			PoolAllocator(void *data, const char * name, Allocator *parent = 0) :
				BasicAllocator(illib::System::align<T>(sizeof(T)), illib::System::allocator().pagesize(), alignof(T), 0),
				data_(data),
				name_(name)
			{

			}
			virtual ~PoolAllocator(){

			}
			T& create() {
				size_t allocatedSize;
				uint8_t * memory = BasicAllocator::allocate(illib::System::align<T>(sizeof(T)), allocatedSize);
				return *new(memory)T();
			}
			bool release(T* ptr){
				return BasicAllocator::release(ptr);
			}
			virtual void * data(){
				return data_;
			}
			virtual const char * name(){
				return name_;
			}
		};
	}
}

#endif
